/* ----------------------------------------------------------------------
*
* Copyright (C) 2025 XiaoFei. All rights reserved.
*
* $file:		TaoJingChi_HMI.h
* $Date:        13-March-2025
* $Revision: 	V1
* $Project: 	XiaoFei BSP Library
* $Taobao:      https://item.taobao.com/item.htm?abbucket=17&id=582620144101
*
* -------------------------------------------------------------------- */

#ifndef __TaoJingChi_HMI_H
#define __TaoJingChi_HMI_H

#define HMI_AddRX
#define HMI_RCC_Usart(x)                RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, (FunctionalState)x)
#define HMI_RCC_TX(x)                   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, (FunctionalState)x)
#define HMI_Usart                       USART1
#define HMI_GPIO_TX                     GPIOA
#define HMI_Pin_TX                      GPIO_Pin_9
#define HMI_BaudRate                    115200

#ifdef HMI_AddRX
    #define HMI_RCC_RX(x)               RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, (FunctionalState)x)
    #define HMI_GPIO_RX                 GPIOA
    #define HMI_Pin_RX                  GPIO_Pin_10
    #define HMI_Group                   NVIC_PriorityGroup_2
    #define HMI_IRQn                    USART1_IRQn
    #define HMI_IRQHandler              USART1_IRQHandler
    #define HMI_ITPre                   1
    #define HMI_ITSub                   1
#endif

#ifndef HMI_BufDef_def
#define HMI_BufDef_def
typedef struct
{
    unsigned char* buf;         /*!< The receved HMI Data buffer */
    unsigned int len_max;       /*!< The max length of HMI data */
    unsigned int len;           /*!< The current length of HMI data */
} HMI_BufDef;
#endif

/* 
* @function: 	HMI_BufClear
* @parameter:	[in] HMI_Buf				The handle of HMI.
* @parameter:	[in] ClThis				    Input 0x01 to clear all buffers, otherwise input 0x00.
*/
void HMI_BufClear(HMI_BufDef* HMI_Buf, unsigned char ClThis);

/* 
* @function: 	HMI_BufGet
* @parameter:	[in] HMI_Buf				The handle of HMI.
* @parameter:	[in] us				        The interval for obtaining two adjacent pointers.
* @return:		Return 0x01 if the data has get successful, otherwise return 0x00.
*/
unsigned char HMI_BufGet(HMI_BufDef* HMI_Buf, unsigned int us);

/* 
* @function: 	HMI_Init
* @parameter:	[out] HMI_Buf				The handle of HMI.
* @parameter:	[in] len				    The max length of HMI data.
*/
void HMI_Init(HMI_BufDef* HMI_Buf, unsigned int len);

/* 
* @function: 	HMI_Printf
* @parameter:	[in] format					 The parameter will be send to HMI.
*/
void HMI_Printf(char* format, ...);

#ifdef HMI_AddRX
/* 
* @function: 	HMI_IRQHandler
* @callback:	The function will be callback when get the data from HMI.
*/
void HMI_IRQHandler(void);
#endif

#endif


